package com.yingxin.yxerp.module.activiti.biz.vo.resp;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yingxin.yx.framework.commons.activiti.ApprovalStatusHelper;
import com.yingxin.yx.framework.commons.constant.CommonConst;
import com.yingxin.yx.framework.commons.dto.AttachmentDto;
import com.yingxin.yx.framework.commons.enums.BusinessType;
import com.yingxin.yx.framework.commons.helper.DateHelper;
import com.yingxin.yx.framework.commons.utlis.AmtFormat;
import com.yingxin.yx.framework.commons.vo.CommonRespVo;
import com.yingxin.yx.framework.render.core.RenderColumn;
import com.yingxin.yx.framework.render.core.RenderForm;
import com.yingxin.yxerp.module.common.BusinessTypeHelper;
import com.yingxin.yxerp.module.sys.vo.resp.DataUpdatePenaltySetRespVo;
import io.swagger.annotations.ApiModel;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.lang3.StringUtils;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * 编辑申请
 * @author yuebao
 * @since 2023-05-22
 */

@Data
@EqualsAndHashCode(callSuper = true)
@ApiModel(value = "UpdateDateApplyRespVo对象", description = "编辑申请")
@RenderForm(name = "编辑申请")
public class UpdateDateApplyRespVo extends CommonRespVo {

    private static final long serialVersionUID = 1L;

    /**
     * id
     */
    private String id;

    /**
     * 申请编号
     */
    @RenderColumn(name = "申请单号", sort = 1, isToDoList = true )
    private String applyNo;

    /**
     * 创建人id
     */
    private String creatorId;

    @RenderColumn(name = "申请人", sort = 2)
    private String creatorName;

    /**
     * 申请时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm", timezone = "GMT+8")
    private Date createTime;

    @RenderColumn(name = "申请时间", sort = 3, isRow = true, isToDoList = true )
    private String createTimeFormat;

    public String getCreateTimeFormat(){
        return DateHelper.dateFormat( createTime, DateHelper.YYYYMMDDHHMMSS );
    }

    /**
     * 发生时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date occurrenceTime;

    @RenderColumn(name = "发生时间", sort = 4, isRow = true, isToDoList = true )
    private String occurrenceTimeFormat;

    public String getOccurrenceTimeFormat(){
        return DateHelper.dateFormat( occurrenceTime, DateHelper.YYYYMMDDHHMMSS );
    }

    /**
     * 单据类型
     */
    private String applyType;

    public String getApplyType(){
        return BusinessType.XGSQ.getType();
    }

    /**
     * 业务 id
     */
    private String businessId;

    /**
     * 业务 no
     */
    @RenderColumn(name = "业务单号", sort = 5, isToDoList = true )
    private String businessNo;

    /**
     * 业务类型
     */
    private String businessType;

    /**
     * 业务类型
     */
    @RenderColumn(name = "业务类型", sort = 6, isToDoList = true )
    private String businessTypeName;

    public String getBusinessTypeName() {
        return BusinessTypeHelper.getName(businessType);
    }

    /**
     * 审核状态 0 审核中 1 通过 -1 未通过
     */
    private String approvalStatus;

    /**
     * 审核状态
     */
    @RenderColumn(name = "审核状态", sort = 7)
    private String approvalStatusName;

    public String getApprovalStatusName() {
        return ApprovalStatusHelper.getName(approvalStatus);
    }

    /**
     * 责任人ID
     */
    private String personResponsibleId;

    /**
     * 责任人
     */
    @RenderColumn(name = "责任人", sort = 8, isToDoList = true )
    private String personResponsibleName;

    /**
     * 部门ID
     */
    private String deptId;

    /**
     * 部门名称
     */
    @RenderColumn(name = "部门", sort = 9, isToDoList = true )
    private String departmentName;

    /**
     * 是否罚款： 0 否，1 是
     */
    private String isPenalty;

    /**
     * 是否罚款
     */
    @RenderColumn(name = "是否罚款", sort = 10 )
    private String isPenaltyName;

    public String getIsPenaltyName(){
        if( StringUtils.isNotEmpty( isPenalty ) ){
            if( CommonConst.FALSE.equals( isPenalty ) ){
                return "否";
            }
            if( CommonConst.TRUE.equals( isPenalty ) ){
                return "是";
            }
        }
        return null;
    }

    /**
     * 罚款金额
     */
    private BigDecimal penaltyMoney;

    @RenderColumn(name = "罚款金额", sort = 11)
    private String penaltyMoneyFormat;

    public String getPenaltyMoneyFormat(){
        return AmtFormat.amtTo( penaltyMoney );
    }

    /**
     * 免罚原因
     */
    @RenderColumn(name = "免罚原因", sort = 12, isRow = true )
    private String avoidPenaltyReason;

    /**
     * 修改原因
     */
    @RenderColumn(name = "修改原因", sort = 13, isRow = true, isToDoList = true)
    private String reason;

    /**
     * 改前描述
     */
    @RenderColumn(name = "改前描述", sort = 14,isRow = true)
    private String updateFrontRemarks;

    /**
     * 改后描述
     */
    @RenderColumn(name = "改后描述", sort = 15,isRow = true)
    private String updateAfterRemarks;

    /**
     * 单据的原来状态
     */
    private String originalFlag;

    /**
     * 改后的对象
     * 序列化
     */
    private String bill;

    /**
     * 改后的对象集
     * 序列化
     */
    private String items;

    /**
     * 改后的对象
     * json
     */
    private String billJson;

    /**
     * 改后的对象集
     * json
     */
    private String itemsJson;

    /**
     * 改前附件
     * json
     */
    private String oldAttachmentJson;

    /**
     * 改前附件 - list
     */
    private List<AttachmentDto> oldAttachmentList;

    public List<AttachmentDto> getOldAttachmentList() {
        if( StringUtils.isNotEmpty( oldAttachmentJson ) ){
            try {
                return new ObjectMapper().readValue( oldAttachmentJson, new TypeReference<List<AttachmentDto>>(){});
            } catch (JsonProcessingException e) {
                throw new RuntimeException(e);
            }
        }
        return null;
    }

    /**
     * 改后附件
     * json
     */
    private String newAttachmentJson;

    /**
     * 改后附件 - list
     */
    private List<AttachmentDto> newAttachmentList;

    public List<AttachmentDto> getNewAttachmentList() {
        if( StringUtils.isNotEmpty( oldAttachmentJson ) ){
            try {
                return new ObjectMapper().readValue( newAttachmentJson, new TypeReference<List<AttachmentDto>>(){});
            } catch (JsonProcessingException e) {
                throw new RuntimeException(e);
            }
        }
        return null;
    }

    /**
     * 热轧代工轧硬是否入本公司： 0 是， 1 否
     * 1 时编辑申请走特殊流程，说明是安融销售部的业务
     */
    private String isInMyCompany;

    /**
     * 更新者id
     */
    private String updaterId;

    /**
     * 更新人
     */
    private String updaterName;

    /**
     * 更新时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm", timezone = "GMT+8")
    private Date updateTime;

    /**
     * 处罚信息 - 默认信息
     */
    private DataUpdatePenaltySetRespVo dataUpdatePenaltySetRespVo;

    /**
     * 处罚信息集合
     */
    private List<DataUpdatePenaltySetRespVo> dataUpdatePenaltySetRespVos;

    /**
     * 修改次数
     */
    private Integer dataNum;

    //    public String getBusinessId() {
    //        return id;
    //    }
    //
    //    public String getBusinessNo() {
    //        return applyNo;
    //    }
    //
    //    public String getBusinessType() {
    //        return BusinessType.XGSQ.getType();
    //    }

    public String getBillTypeName(){
        return BusinessType.XGSQ.getTypeName();
    }

}
